var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "maishu-jueying", "./component", "components/common/base-component", "mobile/services/shoppingService", "./product-source-editor", "components/common/custom-prop-editors"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    const maishu_jueying_1 = require("maishu-jueying");
    const component_1 = require("./component");
    const base_component_1 = require("components/common/base-component");
    const shoppingService_1 = require("mobile/services/shoppingService");
    const product_source_editor_1 = require("./product-source-editor");
    const custom_prop_editors_1 = require("components/common/custom-prop-editors");
    let shoppingService = base_component_1.createService(shoppingService_1.ShoppingService);
    let imageSize = "imageSize";
    let productNameLines = "productNameLines";
    let productSourceType = "productSourceType";
    let productIds = "productIds";
    maishu_jueying_1.Component.setPropEditor({
        componentType: component_1.SingleColunmProducts.name,
        propName: productSourceType,
        editorType: maishu_jueying_1.PropEditor.dropdown({
            "all": "所有商品",
            "category": "品类",
            "custom": "手动添加"
        }),
        displayName: "数据来源",
    });
    maishu_jueying_1.Component.setPropEditor({
        componentType: component_1.SingleColunmProducts,
        propName: productIds,
        editorType: product_source_editor_1.ProductSourceEditor,
        display: (componentData) => {
            let props = componentData.props;
            return props.productSourceType == "custom";
        },
        displayName: "选取商品"
    });
    let categoryId = "categoryId";
    maishu_jueying_1.Component.setPropEditor({
        componentType: component_1.SingleColunmProducts,
        propName: categoryId,
        editorType: maishu_jueying_1.PropEditor.dropdown(getCategories(), "string"),
        displayName: "品类",
        display: (componentData) => {
            let props = componentData.props;
            return props.productSourceType == "category";
        }
    });
    maishu_jueying_1.Component.setPropEditor({
        componentType: component_1.SingleColunmProducts.name,
        propName: imageSize,
        editorType: maishu_jueying_1.PropEditor.dropdown({
            small: "小",
            medium: "中",
            large: "大"
        }),
        displayName: "图片大小",
    });
    maishu_jueying_1.Component.setPropEditor({
        componentType: component_1.SingleColunmProducts.name,
        propName: productNameLines,
        editorType: maishu_jueying_1.PropEditor.dropdown({
            singleLine: "单行文字",
            doubleColumn: "双行文字"
        }),
        displayName: "商品名称",
    });
    let productsCount = "productsCount";
    // let dropdownValues: ComponentProps["productsCount"][] = [1, 2, 3, 4, 5, 6, 7, 8, 0];
    maishu_jueying_1.Component.setPropEditor({
        componentType: component_1.SingleColunmProducts,
        propName: productsCount,
        editorType: maishu_jueying_1.PropEditor.dropdown(Promise.resolve([
            { text: "1", value: 1 },
            { text: "2", value: 2 },
            { text: "3", value: 3 },
            { text: "4", value: 4 },
            { text: "5", value: 5 },
            { text: "6", value: 6 },
            { text: "7", value: 7 },
            { text: "8", value: 8 },
            { text: "全部", value: 2000 },
        ]), "number"),
        displayName: "商品数量",
    });
    let showCategories = "showCategories";
    maishu_jueying_1.Component.setPropEditor({
        componentType: component_1.SingleColunmProducts,
        propName: showCategories,
        editorType: custom_prop_editors_1.toggle({ defaultValue: component_1.SingleColunmProducts.defaultProps.showCategories }),
        displayName: "显示类别"
    });
    function getCategories() {
        return __awaiter(this, void 0, void 0, function* () {
            let categories = (yield shoppingService.categories()) || [];
            let items = categories.map(o => ({ text: o.Name, value: o.Id }));
            items.unshift({ text: "全部品类", value: "" });
            return items;
        });
    }
});
